package com.junzhiit.nengji.app.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.app.service.ShopService;
import com.junzhiit.nengji.app.web.vo.ResultVO;
import com.junzhiit.nengji.app.web.vo.ShopEditVO;
import com.junzhiit.nengji.app.web.vo.ShopUpdateVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/shop")
public class ShopController extends BaseController {

	@Autowired
	private ShopService shopService;

	@ApiOperation(value="获得商户")
	@RequestMapping(value="/session",method=RequestMethod.GET)
	public ResultVO findById(String sessionId){
		return shopService.findById(sessionId);
	}

	@ApiOperation(value = "更新门店信息")
	@RequestMapping(method = RequestMethod.PUT)
	public ResultVO update(ShopUpdateVO shopUpdateVO) {
		AssertUtil.notBlank(shopUpdateVO.getSessionId(), "sessionId is required.");
		return shopService.update(shopUpdateVO);
	}

	@ApiOperation(value = "编辑店铺信息")
	@RequestMapping(value = "/edit", method = RequestMethod.PUT)
	public ResultVO editShop(ShopEditVO shopEditVO) {
		return shopService.editShop(shopEditVO);
	}

	@ApiOperation(value = "删除店铺头像信息")
	@RequestMapping(value = "/head/img", method = RequestMethod.PUT)
	public ResultVO delShopHeadImgUrl(String shopHeadImgUrl, String sessionId) {
		AssertUtil.notBlank(sessionId, "sessionId is required.");
		AssertUtil.notBlank(shopHeadImgUrl, "shopHeadImgUrl is required.");
		return shopService.delShopHeadImgUrl(shopHeadImgUrl, sessionId);
	}
	
	@ApiOperation(value = "删除店铺背景图片")
	@RequestMapping(value = "/background/image", method = RequestMethod.PUT)
	public ResultVO delBackgroundImage(String backgroundImage, String sessionId) {
		AssertUtil.notBlank(sessionId, "sessionId is required.");
		AssertUtil.notBlank(backgroundImage, "shopHeadImgUrl is required.");
		return shopService.delBackgroundImage(backgroundImage, sessionId);
	}

	@ApiOperation(value = "删除店铺广告图片信息")
	@RequestMapping(value = "/banner/img", method = RequestMethod.PUT)
	public ResultVO delBannerImages(String bannerImage, String sessionId) {
		AssertUtil.notBlank(sessionId, "sessionId is required.");
		AssertUtil.notBlank(bannerImage, "bannerImage is required.");
		return shopService.delBannerImages(bannerImage, sessionId);
	}
	
	@ApiOperation(value = "生成店铺二维码")
	@RequestMapping(value = "/create/qrcode", method = RequestMethod.POST)
	public ResultVO createQrcode(String sessionId) {
		AssertUtil.notBlank(sessionId, "sessionId is required.");
		return shopService.createQrcode(sessionId);
	}
	
}
